package com.example.wechat114.service.impl;

import com.example.wechat114.commons.JsonBean;
import com.example.wechat114.entity.Thepatients;
import com.example.wechat114.mapper.ThepatientsMapper;
import com.example.wechat114.service.ThepatientsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.plaf.nimbus.NimbusLookAndFeel;
import java.util.List;

@Service
public class ThepatientsServiceImpl implements ThepatientsService {
    @Autowired
    private ThepatientsMapper thepatientsMapper;

    @Override
    public JsonBean addThepatiens(Thepatients thepatients) {
        JsonBean jsonBean = new JsonBean(-1, "添加失败", null);
        int insert = thepatientsMapper.insert(thepatients);
        if(insert>0){
            jsonBean = new JsonBean(0, "添加成功", null);
        }

        return jsonBean;
    }

    @Override
    public JsonBean selectAll() {
        JsonBean jsonBean = new JsonBean(-1, "", null);
        List<Thepatients> thepatients = thepatientsMapper.selectAll();
        if(thepatients.size()>0){
            jsonBean = new JsonBean(0, "", thepatients);
        }

        return jsonBean;
    }

    @Override
    public JsonBean selectById(Integer id) {
        JsonBean jsonBean = new JsonBean(-1, "", null);
        Thepatients thepatients = thepatientsMapper.selectById(id);
        if(thepatients!=null){
            jsonBean = new JsonBean(0, "", thepatients);
        }
        return jsonBean;
    }

    @Override
    public JsonBean selectByopenid(String openid) {
        return new JsonBean(0,"",thepatientsMapper.selectByOpenid(openid));
    }

    @Override
    public JsonBean selectByidcard(String idcard) {
        return new JsonBean(0,"",thepatientsMapper.selectBycard(idcard));
    }
}
